<extend name="api/body" />
<block name="body">
	<div class="card" style="margin-top:10px;">
		<form action="<?=url(request()->controller().'/'.request()->action())?>" method="post" class="js_form card-body">
			<input type="hidden" name="project_id" value="<?=input('project_id')?input('project_id'):$info['project_id']?>" />
			<input type="hidden" name="id" value="<?=$info['id']?>" />
			<div class="row">
				<div class="form-group col-4">
					<label>所属模块</label>
					<select name="pid" class="form-control">
						<?php
							foreach($module_list as $row){
						?>
						<option value="<?=$row['id']?>" <?=($row['id']==$info['pid'] || $row['id']==input('pid'))?'selected':''?>><?=$row['title']?></option>
						<?php
							}
						?>
					</select>
				</div>
				<div class="form-group col-8">
					<label>接口名称</label>
					<input type="text" name="title" value="<?=$info['title']?>" class="form-control" />
				</div>
			</div>
			<div class="row">
				<div class="form-group col-4">
					<label>请求类型</label>
					<select name="request_type" class="form-control" >
						<option value="get" <?=$info['request_type']=='get'?'selected':''?>>GET</option>
						<option value="post" <?=$info['request_type']=='post'?'selected':''?>>POST</option>
					</select>
				</div>
				<div class="form-group col-8">
					<label>接口地址</label>
					<input type="text" name="api_url" value="<?=$info['api_url']?>" class="form-control" placeholder="模块/控制器/方法" />
				</div>
			</div>
			<div class="form-group">
				<label>备注说明</label>
				<textarea name="remark" class="form-control" rows="3" placeholder="Enter..."><?=$info['remark']?></textarea>
			</div>
			<!-- Table -->
			<table class="table table-form">
				<thead>
					<tr>
						<th width="200">参数名称</th>
						<th width="100" class="text-center">参数类型</th>
						<th width="100" class="text-center">是否必须</th>
						<th width="100" class="text-center">默认值</th>
						<th>参数说明</th>
						<th width="100" class="text-center">填充示例</th>
						<th width="120" class="text-center">顺序</th>
						<th width="60" class="text-center">操作</th>
					</tr>
				</thead>
				<tbody>
					<?php
						if($api_info){
							foreach($api_info as $val){
					?>
					<tr>
						<td><input type="text" name="api_param[name][]" class="form-control form-control-sm" value="<?=$val['name']?>" ></td>
						<td class="text-center">
							<select name="api_param[type][]" class="form-control form-control-sm">
								<option value="string" <?=$val['type']=='string'?'selected':''?>>string</option>
								<option value="int" <?=$val['type']=='int'?'selected':''?>>int</option>
								<option value="file" <?=$val['type']=='file'?'selected':''?>>file</option>
							</select>
						</td>
						<td class="text-center">
							<select name="api_param[is_require][]" class="form-control form-control-sm">
								<option value="yes" <?=$val['is_require']=='yes'?'selected':''?>>必填</option>
								<option value="no" <?=$val['is_require']=='no'?'selected':''?>>选填</option>
							</select>
						</td>
						<td><input type="text" name="api_param[default][]" class="form-control form-control-sm text-center" value="<?=$val['default']?>" ></td>
						<td><input type="text" name="api_param[remark][]" class="form-control form-control-sm" value="<?=$val['remark']?>" ></td>
						<td><input type="text" name="api_param[demo][]" class="form-control form-control-sm text-center" value="<?=$val['demo']?>" ></td>
						<td class="text-center">
							<a href="javascript:void(0);" class="js_move_up btn btn-sm btn-outline-primary">上移</a>
							<a href="javascript:void(0);" class="js_move_down btn btn-sm btn-outline-info">下移</a>
						</td>
						<td class="text-center">
							<a href="javascript:void(0);" class="js_del_param btn btn-sm btn-outline-danger">删除</a>
						</td>
					</tr>
					<?php
							}
						}
					?>
				</tbody>
				<tfoot>
					<tr>
						<td colspan="8" align="center">
							<a href="javascript:void(0);" class="js_add_param btn btn-sm btn-outline-primary">+ 新增参数</a>
						</td>
					</tr>
				</tfoot>
			</table>
			<div class="form-group">
				<div class="control-label">接口返回数据说明</div>
				<textarea name="return_param" autoHeight="true" class="form-control" rows="10" style="overflow:hidden;"><?=$info['return_param']?></textarea>
			</div>
			<div class="form-group">
				<label>排序</label>
				<input type="text" name="sort" value="<?=$info['sort']?>" class="form-control width_auto" placeholder="排序" />
			</div>
			<div class="form-btn row">
				<div class="js_validTips" style="flex:1;height:34px;line-height:34px;"><span class="js_tipContent Validform_checktip">&nbsp;</span></div>
				<div style="flex:1;text-align:right;">
					<input type="submit" class="btn btn-primary" value="提交" />
					<a href="javascript:void(0);" data-id="cancel" class="btn btn-secondary">取消</a>
				</div>
			</div>
		</form>
	</div>
</block>
<block name="js">
<script type="text/javascript">
$(function(){
	$(".js_add_param").on("click",function(){
		var html='<tr>'
				+'<td><input type="text" name="api_param[name][]" class="form-control form-control-sm" ></td>'
				+'<td><select name="api_param[type][]" class="form-control form-control-sm"><option value="string">string</option><option value="int">int</option><option value="file">file</option></select></td>'
				+'<td class="text-center"><select name="api_param[is_require][]" class="form-control form-control-sm"><option value="yes">必填</option><option value="no">选填</option></select></td>'
				+'<td><input type="text" name="api_param[default][]" class="form-control form-control-sm" ></td>'
				+'<td><input type="text" name="api_param[remark][]" class="form-control form-control-sm" ></td>'
				+'<td><input type="text" name="api_param[demo][]" class="form-control form-control-sm" ></td>'
				+'<td class="text-center"><a href="javascript:void(0);" class="js_move_up btn btn-sm btn-outline-primary">上移</a> <a href="javascript:void(0);" class="js_move_down btn btn-sm btn-outline-info">下移</a></td>'
				+'<td class="text-center"><a href="javascript:void(0);" class="js_del_param btn btn-sm btn-outline-danger">删除</a></td>'
			+'</tr>';
		$(this).parents('tfoot').prev().append(html);
	})
	$(document).on("click",".js_del_param",function(){
		$(this).parent().parent().remove();
	})
    $.fn.autoHeight = function(){    
        function autoHeight(elem){
            elem.style.height = elem.scrollHeight+30 + 'px';
        }
        this.each(function(){
            autoHeight(this);
            $(this).on('keyup', function(){
                autoHeight(this);
            });
        });
    }
    $('textarea[autoHeight]').autoHeight();
    $(document).on("click",".js_move_up",function(){
    	$(this).parents('tr').css("background","#edfdeb").siblings('tr').removeAttr("style");
    	$(this).parents('tr').prev().before($(this).parents('tr'));
    })
    $(document).on("click",".js_move_down",function(){
    	$(this).parents('tr').css("background","#edfdeb").siblings('tr').removeAttr("style");
    	$(this).parents('tr').next().after($(this).parents('tr'));
    })
})


</script>
</block>